<?php
error_reporting(7);


if (!$_GET['action'] AND !$_POST['action']) {
        $_GET['action'] = "view";
} 

if ($_GET['action'] == "view") {
        $template_name = "case_view.htm";
        require "common.php";
        require "tools/case/class.case.php";
        $cate=$_POST["cate"];
        $names=$_POST["names"];
        $add_time=$_POST["add_time"];
        $operator=$_POST["operator"];

        // START 检查权限
        if (!$perm->check_permission(PRODUCTS, PRODUCTS_VIEW)) {
                display_nopermission();
        }
        // END 检查权限
        ///*****生成分类数据////
        require_once "tools/tree/sort.class.php";
        $tree = new SortClass($DB,'`t_reported_sys`');
        $selecttreelist=$tree->makeTreeSelect(66,"catetree");
        ///*****生成分类数据结束////

        if(!empty($cate)){
            $where.=" and cate='$cate'";
        }
        if(!empty($names)){
            $where.=" and names like %$cate%";
        }
        if(!empty($add_time)){
            $where.=" and add_time>'$add_time'";
        }
        if(!empty($operator)){
            $where.=" and operator='$operator'";
        }

        $case=new CASES($DB);
        $result=$case->show($where);
        $tpl->assign($case->pager->result);
        $tpl->assign("selecttreelist",$selecttreelist);
        $tpl->assign("results", $result);
        $tpl->output();
}
if($_GET['action'] == "addview"){
    $template_name = "case_add.htm";
    require "common.php";
    ///*****生成分类数据////
    require_once "tools/tree/sort.class.php";
    $tree = new SortClass($DB,'`t_reported_sys`');
    $selecttreelist=$tree->makeTreeSelect(66,"catetree");
    ///*****生成分类数据结束////
    $tpl->assign("selecttreelist",$selecttreelist);
    $tpl->output();
}
if($_GET['action'] == "editview"){
    $template_name = "products_edit.htm";
    require "common.php";
    require "tools/case/class.case.php";
    ///*****生成分类数据////
    require_once "tools/tree/sort.class.php";
    $tree = new SortClass($DB,'`t_reported_sys`');
    $selecttreelist=$tree->makeTreeSelect(66,"catetree");
    ///*****生成分类数据结束////
    $product=new PRODUCTS($DB);
    $result=$product->getProductsByid($_GET['id']);
    $tpl->assign("selecttreelist",$selecttreelist);
    $tpl->assign($result);
    $tpl->output();
}
if($_GET['action']=="add"){
    require "common.php";
    require "tools/case/class.case.php";
    $case=new CASES($DB);
    $id=$_POST["id"];
    $pname=$_POST["pname"];
    $catetree=$_POST["catetree"];
    $sort=$_POST["sort"];
    $imgid=trim($_POST["imgid"],"|");
    $pdesc=$_POST["pdesc"];
    $result=$case->add($id,$pname,$catetree,$sort,$imgid,$pdesc);

     redirect("./case.php?action=view", "添加成功！");
}